package com.qfedu.openplateform.manager.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.openplateform.manager.entity.AjaxMessage;
import com.qfedu.openplateform.manager.entity.AppInfo;
import com.qfedu.openplateform.manager.entity.TableData;
import com.qfedu.openplateform.manager.service.AppInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/sys/app_info")
@RestController
public class AppInfoController {

    @Autowired
    private AppInfoService appInfoService;

    /**
     * 查询所有+分页
     *
     * @param page
     * @param limit
     * @return
     */
    @RequestMapping("/table")
    public TableData table(Integer page, Integer limit, String corpName) {
        System.out.println("黄涛是傻逼");
        if (corpName == null) {
            PageHelper.startPage(page, limit);
            List<AppInfo> appInfoList = appInfoService.findAll();
            PageInfo<AppInfo> info = new PageInfo(appInfoList);
            TableData<AppInfo> appInfoTableData = new TableData<>(info.getTotal(), info.getList());
            return appInfoTableData;
        } else {
            PageHelper.startPage(page, limit);
            List<AppInfo> appInfoList = appInfoService.findByLikeName(corpName);
            PageInfo<AppInfo> info = new PageInfo(appInfoList);
            System.out.println(info);
            TableData<AppInfo> appInfoTableData = new TableData(info.getTotal(), info.getList());
            return appInfoTableData;
        }

    }

    /**
     * 删除
     *
     * @param ids
     * @return
     */
    @RequestMapping("/del")
    public AjaxMessage deleteAppInfo(Integer[] ids) {
        appInfoService.deleteAppInfo(ids);
        return new AjaxMessage(true, "删除成功");
    }

    /**
     * 添加
     *
     * @param appInfo
     */
    @RequestMapping("/add")
    public void add(AppInfo appInfo) {
        appInfoService.add(appInfo);
    }

    @RequestMapping("/update")
    public void update(AppInfo appInfo) {
        appInfoService.update(appInfo);
    }

//    /**
//     * 模糊查询
//     *
//     * @param page
//     * @param limit
//     * @return
//     */
//    @RequestMapping("/table")
//    public TableData table(Integer page, Integer limit, String corpName) {
//        PageHelper.startPage(page, limit);
//        List<AppInfo> appInfoList = appInfoService.findByLikeName(corpName);
//        PageInfo<AppInfo> info = new PageInfo(appInfoList);
//        TableData<AppInfo> appInfoTableData = new TableData(info.getTotal(), info.getList());
//        return appInfoTableData;
//    }

}
